SET NOCOUNT ON
SET QUOTED_IDENTIFIER ON
GO

ALTER TABLE [dbo].[tblMatches]  WITH CHECK ADD  CONSTRAINT [CK_tblMatches_FieldRequired] CHECK  (([mat_Field] IS NULL OR [mat_From] IS NOT NULL AND [mat_To] IS NOT NULL))
GO

DELETE FROM [tblUFGSearchFilters] WHERE [usf_TableName] = 'tblMatches'
GO
INSERT INTO [IMAGine].[dbo].[tblUFGSearchFilters]
           ([usf_SearchFilterName]
           ,[usf_SearchFilterType]
           ,[usf_SearchFilterCondition]
           ,[usf_RoleName]
           ,[usf_UserName]
           ,[usf_TableName]
           ,[usf_IsWork]
           ,[usf_Message]
           ,[usf_Published]
           ,[usf_Category]
           ,[usf_PublishedBlock])
     VALUES
           ('MatchesForPlanning','Role','mat_Field is null','Wedstrijdsecretariaat Club',null,'tblMatches',1,'SF_MatchesForPlanning',0,null,'NONE'),
           ('AlertForMatchPlanning','Role','mat_Field is null AND mat_Date > DateAdd(day, -2, getdate())','Wedstrijdsecretariaat Club',null,'tblMatches',1,'SF_AlertForMatchPlanning',0,null,'NONE'),
           ('AlertForMatchReferees','Role','mat_Date > DateAdd(day, -14, getdate()) AND NOT EXISTS (SELECT * FROM tblMatchReferees WHERE mrf_HomeClubname = mat_HomeClubname AND mrf_HomeSeason = mat_HomeSeason AND mrf_HomeTeamName = mat_HomeTeamName AND mrf_AgainstClubname = mat_AgainstClubname AND mrf_AgainstSeason = mat_AgainstSeason AND mrf_AgainstTeamName = mat_AgainstTeamName)','Scheidsrechterscommissie Club',null,'tblMatches',1,'SF_AlertForMatchReferees',0,null,'NONE')
GO

DELETE FROM dbo.tblUFGMessages WHERE umm_MessageName IN ('SF_MatchesForPlanning','SF_AlertForMatchPlanning')
GO
INSERT dbo.tblUFGMessages (umm_MessageName, umm_LanguageName, umm_Message)
VALUES ('SF_MatchesForPlanning', 'Nederlands', 'Nieuwe wedstrijden planbaar.'),
	   ('SF_AlertForMatchPlanning', 'Nederlands', 'Aankomende wedstrijden niet gepland.'),
	   ('SF_AlertForMatchReferees', 'Nederlands', 'Aankomende wedstrijden zonder scheidsrechters.')
GO


